package com.ruoyi.web.controller.basic;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BasicMessageType;
import com.ruoyi.system.service.IBasicMessageTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息类型Controller
 * 
 * @author ruoyi
 * @date 2025-03-02
 */
@RestController
@RequestMapping("/system/basicMessageType")
public class BasicMessageTypeController extends BaseController
{
    @Autowired
    private IBasicMessageTypeService basicMessageTypeService;

    /**
     * 获取消息类型字典列表
     * @return
     */
    @GetMapping("/getMessageTypeDictList")
    public AjaxResult getMessageTypeDictList() {
        BasicMessageType basicMessageType = new BasicMessageType();
        basicMessageType.setIsEnabled(1); // 启用
        List<BasicMessageType> basicMessageTypeList = basicMessageTypeService.selectBasicMessageTypeList(basicMessageType);
        return AjaxResult.success(basicMessageTypeList);
    }

    /**
     * 查询消息类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:basicMessageType:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicMessageType basicMessageType)
    {
        startPage();
        List<BasicMessageType> list = basicMessageTypeService.selectBasicMessageTypeList(basicMessageType);
        return getDataTable(list);
    }

    /**
     * 导出消息类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:basicMessageType:export')")
    @Log(title = "消息类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicMessageType basicMessageType)
    {
        List<BasicMessageType> list = basicMessageTypeService.selectBasicMessageTypeList(basicMessageType);
        ExcelUtil<BasicMessageType> util = new ExcelUtil<BasicMessageType>(BasicMessageType.class);
        util.exportExcel(response, list, "消息类型数据");
    }

    /**
     * 获取消息类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:basicMessageType:query')")
    @GetMapping(value = "/{messageTypeId}")
    public AjaxResult getInfo(@PathVariable("messageTypeId") Long messageTypeId)
    {
        return success(basicMessageTypeService.selectBasicMessageTypeByMessageTypeId(messageTypeId));
    }

    /**
     * 新增消息类型
     */
    @PreAuthorize("@ss.hasPermi('system:basicMessageType:add')")
    @Log(title = "消息类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicMessageType basicMessageType)
    {
        return toAjax(basicMessageTypeService.insertBasicMessageType(basicMessageType));
    }

    /**
     * 修改消息类型
     */
    @PreAuthorize("@ss.hasPermi('system:basicMessageType:edit')")
    @Log(title = "消息类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicMessageType basicMessageType)
    {
        return toAjax(basicMessageTypeService.updateBasicMessageType(basicMessageType));
    }

    /**
     * 删除消息类型
     */
    @PreAuthorize("@ss.hasPermi('system:basicMessageType:remove')")
    @Log(title = "消息类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageTypeIds}")
    public AjaxResult remove(@PathVariable Long[] messageTypeIds)
    {
        return toAjax(basicMessageTypeService.deleteBasicMessageTypeByMessageTypeIds(messageTypeIds));
    }
}
